home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TDE.ARJ / TDEDEMO.CPP < prev    next >
C/C++ Source or Header  |  1992-07-14  |  8KB  |  265 lines

  1. /***************************************************************************
  2.  
  3.  FILENAME - TDEDEMO.CPP: Demonstration of TDataEntry objects.
  4.  ----------------------
  5.  
  6.  Class TDataEntry v1.0 - 07/14/92
  7.  --------------------------------
  8.  
  9.  ----------------------------------------------------------------------------
  10.  Author: Jeff Penrose * JDP Custom Software * (818) 344-7303 * CIS 71043,3727
  11.  ----------------------------------------------------------------------------
  12.  
  13.  A data entry class for Borland's Turbo Vision, derived from TInputLine.
  14.  
  15.  Copyright Notice
  16.  ================
  17.   As this material is ultimately derived from Borland source files, any of
  18.  their copyrights which MAY apply DO apply.
  19.   From the author's standpoint, you may use this material freely and,
  20.  hopefully, post any comments/corrections/enhancements to me at the above-
  21.  noted addresses.  I do ask that you not distribute this material except as
  22.  originally received, including all source/documentation files in their
  23.  original form.
  24.   If you DO modify or enhance any of this code, please send any such changes
  25.  to me for incorporation into a future version.  Any such enhancements will
  26.  be DONATED, without expectation of compensation or incorporation into
  27.  future versions.  Again, if you distribute this code, please do so in its
  28.  original, unmodified form including all source files and documentation.
  29.  
  30.  Source files included
  31. =====================
  32.  TDE     .DOC: This documentation.
  33.  TDE     .MAN: How to use TDataEntry in your dialog objects
  34.  TDE     .H  : header file containing class declarations for classes
  35.  TDEFLAGS.H  :   "     "      "       flags and command definitions
  36.  TDE     .CPP: Class TDataEntry
  37.  TDEDATE .CPP: Class TDEDate
  38.  TDEPHONE.CPP: Classes TDEPhone, TDEZipCode, TDEState
  39.  TDENUMS .CPP: Class TDEInteger
  40.  TDECLUST.CPP: Non-TDataEntry classes TDEButton, TDERadioButtons, TDECheckBoxes
  41.  TDEINPLI.CPP: Non-TDataEntry class TDEInputLine
  42.  TDELIB  .PRJ: Project for building library TDELIB.LIB
  43.  TDEDEMO .CPP: Demo program
  44.  TDEDEMO .PRJ: Project for building TDEDEMO.EXE
  45.  
  46. ***************************************************************************/
  47. #define Uses_TEventQueue
  48. #define Uses_TEvent
  49. #define Uses_TProgram
  50. #define Uses_TApplication
  51. #define Uses_TKeys
  52. #define Uses_TRect
  53. #define Uses_TMenuBar
  54. #define Uses_TSubMenu
  55. #define Uses_TMenuItem
  56. #define Uses_TStatusLine
  57. #define Uses_TStatusItem
  58. #define Uses_TStatusDef
  59. #define Uses_TDeskTop
  60. #define Uses_TView
  61. #define Uses_TWindow
  62. #define Uses_TFrame
  63. #define Uses_TScroller
  64. #define Uses_TScrollBar
  65. #define Uses_TDialog
  66. #define Uses_TButton
  67. #define Uses_TSItem
  68. #define Uses_TCheckBoxes
  69. #define Uses_TRadioButtons
  70. #define Uses_TLabel
  71. #define Uses_TInputLine
  72. #define Uses_TCollection
  73. #define Uses_TStringCollection
  74. #include <tv.h>
  75.  
  76. #define  Uses_TDEDate
  77. #define  Uses_TDEZipCode
  78. #define  Uses_TDEPhone
  79. #define  Uses_TDEState
  80. #define  Uses_TDEButton
  81. #include "tde.h"
  82.  
  83. const cmDemo = 200;
  84.  
  85. struct dlgRec
  86. {
  87.   char name[31], add[31], city[31], state[3], zip[10], phn[11];
  88.   unsigned long dob;
  89. } dlgData;
  90.  
  91. //--------------------------------------------------------------------------
  92. // **** class TDemoDialog
  93. //--------------------------------------------------------------------------
  94. class TDemoDialog : public TDialog
  95. {
  96. public:
  97.   TDemoDialog();
  98.   virtual Boolean valid(ushort cmd);
  99. };
  100.  
  101. //--------------------------------------------------------------------------
  102. // **** TDemoDialog::TDemoDialog()
  103. //--------------------------------------------------------------------------
  104. TDemoDialog::TDemoDialog() :
  105.   TDialog(TRect(0,0,68,13), "TDataEntry Demo"),
  106.   TWindowInit(TDemoDialog::initFrame)
  107. {
  108.   TView  *v;
  109.   TDataEntry::globalID = 0;  //* don't forget to set this
  110.   options |= ofCentered;
  111.  
  112.   insert(new TStaticText(TRect(12,2,52,3),
  113.          "This dialog box uses TDataEntry Objects!"));
  114.  
  115.   insert((v = new TDataEntry( 12, 4, 30)));
  116.   insert(new TLabel(TRect(5,4,11,5), "~N~ame:", v));
  117.  
  118.   insert((v = new TDataEntry( 12, 5, 30)));
  119.   insert(new TLabel(TRect(2,5,11,6), "~A~ddress:", v));
  120.  
  121.   insert((v = new TDataEntry( 12, 6, 30)));
  122.   insert(new TLabel(TRect(5,6,11,7), "~C~ity:", v));
  123.  
  124.   insert((v = new TDEState( 12, 7, 2)));
  125.   ((TDataEntry*)v)->localMode |= tdlAutoExit;
  126.   insert(new TLabel(TRect(4,7,11,8), "~S~tate:", v));
  127.  
  128.   insert((v = new TDEZipCode( 32, 7, "~~~~~-~~~~")));
  129.   ((TDataEntry*)v)->localMode |= tdlAutoExit;
  130.   insert(new TLabel(TRect(21,7,31,8), "~Z~ip Code:", v));
  131.  
  132.   insert((v = new TDEPhone( 52, 4, "(~~~) ~~~-~~~~")));
  133.   ((TDataEntry*)v)->localMode |= tdlAutoExit;
  134.   insert(new TLabel(TRect(44,4,51,5), "~P~hone:", v));
  135.  
  136.   insert((v = new TDEDate( 52, 6, "~~/~~/~~")));
  137.   ((TDataEntry*)v)->localMode |= (tdlAutoExit | tdlRequired);
  138.   insert(new TLabel(TRect(46,6,51,7), "~D~OB:", v));
  139.  
  140.   insert(new TDEButton(TRect(12,10,25,12), "~O~k/Save", cmOK, bfDefault));
  141.   insert(new TDEButton(TRect(45,10,55,12), "Cancel", cmCancel, bfNormal));
  142.  
  143.   selectNext(False);
  144. }
  145.  
  146. //--------------------------------------------------------------------------
  147. // **** TDemoDialog::valid()
  148. // Hastily put together.  Wouldn't cut it in real life but it gets the
  149. // idea across.
  150. //--------------------------------------------------------------------------
  151. Boolean TDemoDialog::valid(ushort cmd)
  152. {
  153.   Boolean  isChanged = False;
  154.  
  155.   switch( cmd )
  156.   {
  157.     case cmValid:
  158.      break;
  159.     case cmCancel:
  160.     case cmClose:
  161.     case cmQuit:
  162.     case cmOK:
  163.       if ( TDataEntry::queryChanged(this) )
  164.         isChanged = True;
  165.  
  166.       if ( isChanged && cmd != cmOK )
  167.       {
  168.         cout << (char)7;
  169.         ushort r = messageBox("\003Data has changed! Save?",
  170.                              mfWarning|mfYesNoCancel);
  171.         if ( r == cmNo )
  172.           return True;
  173.         else if ( r == cmCancel )
  174.           return False;
  175.       }
  176.       else if ( cmd != cmOK )
  177.       {
  178.         return True;
  179.       }
  180.  
  181.       //* cmOK
  182.  
  183.       if ( isChanged && TDataEntry::queryValid(this) )
  184.           return False;
  185.       //* save the stuff
  186.       return True;
  187.  
  188.     default:
  189.       break;
  190.   }
  191.   return TDialog::valid(cmd);
  192. }
  193.  
  194.  
  195. //--------------------------------------------------------------------------
  196. // **** class TDEApp
  197. //--------------------------------------------------------------------------
  198. class TDEApp : public TApplication
  199. {
  200. public:
  201.   TDEApp();
  202.   static  TStatusLine *initStatusLine(TRect r);
  203.   virtual void handleEvent(TEvent& event);
  204. };
  205.  
  206. //--------------------------------------------------------------------------
  207. // **** TDEApp::TDEApp()
  208. //--------------------------------------------------------------------------
  209. TDEApp::TDEApp() : TProgInit( TDEApp::initStatusLine,
  210.                           TDEApp::initMenuBar,
  211.                           TDEApp::initDeskTop
  212.                          )
  213. {
  214.   //** Initialize TDataEntry's globalMode
  215.   TDataEntry::globalMode |= (tdgEnterIsTab|tdgUpDownEnable|tdgValidNow);
  216. }
  217.  
  218. //--------------------------------------------------------------------------
  219. // **** TDEApp::initStatusLine()
  220. //--------------------------------------------------------------------------
  221. TStatusLine *TDEApp::initStatusLine( TRect r )
  222. {
  223.   r.a.y = r.b.y - 1;
  224.   return new TStatusLine( r,
  225.     *new TStatusDef(0, 0xFFFF) +
  226.     *new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit) +
  227.     *new TStatusItem("~F4~ TDE Demo", kbF4, cmDemo)
  228.   );
  229. }
  230.  
  231. //--------------------------------------------------------------------------
  232. // **** TDEApp::handleEvent()
  233. //--------------------------------------------------------------------------
  234. void TDEApp::handleEvent(TEvent& event)
  235. {
  236.   TApplication::handleEvent(event);
  237.   if( event.what == evCommand && event.message.command == cmDemo )
  238.   {
  239.     TDemoDialog *d = (TDemoDialog *)validView(new TDemoDialog());
  240.     if( d != 0 )
  241.     {
  242.       d->setData( &dlgData );
  243.       if ( deskTop->execView(d) == cmOK )
  244.         d->getData( &dlgData );
  245.       else
  246.         memset(&dlgData, '\0', sizeof(dlgData));  //* or something
  247.       destroy( d );
  248.     }
  249.     clearEvent(event);
  250.   }
  251. }
  252.  
  253. //--------------------------------------------------------------------------
  254. // **** MAIN ****
  255. //--------------------------------------------------------------------------
  256.  
  257. int main()
  258. {
  259.   TDEApp   DemoApp;
  260.   DemoApp.run();
  261.   return 0;
  262. }
  263.  
  264.  
  265.